<?php
session_start();
include_once "login.php";

if (!isset($_SESSION['userid'])) {
  echo "<br>DEBE INICIAR SESION";
}else{
//muestro el contenido que se debe
?>


<?php
$servername = "localhost";
$username = "yosephaider";
$password = "adminbd";
$dbname = "adv-letsgo";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Conneccion fallida: " . $conn->connect_error);
}


if(! get_magic_quotes_gpc() ){
  $cR = addslashes ($_POST['codRes']);
  $fL = addslashes ($_POST['fechaLlegada']);
  $fS = addslashes ($_POST['fechaSalida']);
  $cH = addslashes ($_POST['codHot']);
  $nC = addslashes ($_POST['nroCed']);
  $nHR = addslashes ($_POST['nroHabRes']);
}else{
  $cR = $_POST['codRes'];
  $fL = $_POST['fechaLlegada'];
  $fS = $_POST['fechaSalida'];
  $cH = $_POST['codHot'];
  $nC = $_POST['nroCed'];
  $nHR = $_POST['nroHabRes'];

}

$sql = "INSERT INTO ReservacionesH (codRes, fechaLlegada, fechaSalida, codHot, nroCed, nroHabRes) VALUES ('$cR', '$fL', '$fS', '$cH', '$nC', '$nHR')";
if ($conn->query($sql) === TRUE) {
    echo "Se inserto correctamente<br>";
    echo '<a href="reser.php">Ok</a>';
} else {
    echo "Error: ".$sql."<br>" .$conn->error;
}


$cambio = "SELECT * FROM `ReservacionesH` WHERE `codHot` LIKE '$cH' AND `nroCed` LIKE '$nC' ";
//Mostramos los registros
if ($result=mysqli_query($conn,$cambio)){
  while($cdr=mysqli_fetch_row($result)){
    $numh = $cdr[5];
    mysqli_query($conn,"UPDATE `adv-letsgo`.`Habitaciones` SET `estado` = 'ocupada' WHERE `Habitaciones`.`nroHab` ='$numh' AND `codHotHab` LIKE '$cH' ");
  }
  mysqli_free_result($result);
}

mysqli_close($conn);
?> 
  


<?php
} 
?>



